<?php
/*
 * @@Copyright (C), 2021-2022: 恒盛时代
 * @Author: zhouzhou
 * @Date: 2022/1/4
 * @Description: im敏感词
 */

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class ImSensitiveWord extends BaseModel
{
    protected $table = 'im_sensitive_word';
    protected $hidden = ['created_at','updated_at'];

    /**
     * @desc 查询是否敏感词
     * @param string $word 敏感词过滤
     * @return array|int
     * @author zhouzhou
     * @time 2022/1/4 10:05
     */
    public function getSensitiveInfo($word)
    {
        if(empty($word))
        {
            return 0;
        }

        $flag = 0;

        $list = $this->where(['is_del' => 0])->get();

        // 去除标点符号
        $char = "。、！？：；﹑•＂…‘’“”〝〞∕¦‖—　〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔！¡？¿﹖﹌﹏﹋＇´ˊˋ―﹫︳︴¯＿￣﹢﹦﹤‐­˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷
            ︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼（）◐▶❤♦☃►-○‿-☃→❧❥⊹✪☞♩✓▣♨✿►ஐ☜☞㊣◎▒♥★❧◎☠❤☭◥✐Θ☄｡◙◈♧，❉☢☎♬❦♈☻☼✚♣☆✟☏✄✦❉۩๑♡♂¤☪ぃ￡♫♯Ю✡✲➹♀
            ❣✡✣✤の✍❀♪☈☊۞あ۞☍♠ღ☣♭♤º✔✎☺❁❃✌✕✖☌§❂❈♮☋✥☇o	〓  ｜";
        $pattern = array(
            "/[[:punct:]]/i", //英文标点符号
            '/['.$char.']/u', //中文标点符号
            '/[ ]{2,}/'
        );
        $str = preg_replace($pattern, '', $word);
        $str = str_replace(" ", '', $str);

        foreach($list as &$value)
        {
            if(preg_match("/{$value['name']}/", $str))
            {
                $flag = ["code"=>1,'msg'=>$value['name']];
                break;
            }

        }

        return $flag;
    }


}
